/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ainlolcat.ainscience;

import org.ainlolcat.ainscience.UI.ExcelStatisticsExporter;
import org.ainlolcat.ainscience.UI.MainWindow;
import org.ainlolcat.ainscience.entity.Entity;
import org.ainlolcat.ainscience.entity.EntityTableModel;
import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;
import org.jdom.JDOMException;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * just for test purpose
 * @author ain
 */
public class main {
    static {
        try{
            Properties props = new Properties();
            props.load(new FileInputStream("./log4j.properties"));
            PropertyConfigurator.configure(props);
        } catch (Throwable t){
            System.out.println("We have a problem: " + t);
        }
    }
    private static Logger log = Logger.getLogger(main.class);

    public static void main(String[] args){
        Map<String,String> parameters = new HashMap();
        for (int i=0;i<args.length;i=i+2){
            if (!args[i].startsWith("-D"))
                parameters.put(args[i], args[i+1]);
        }
        boolean CLI = false;
        if (parameters.containsKey("-mode")){
            if (parameters.get("-mode").equals("cli"))
                CLI = true;
        }
        if (!CLI) {
            MainWindow newwin =  MainWindow.getInstance();
            newwin.setVisible(true);
        }
        if (parameters.containsKey("-load")){
            try {
                Controller.getInstance().loadProject(parameters.get("-load"));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            if (!CLI) MainWindow.getInstance().setTitle(parameters.get("-load"));
            if (parameters.containsKey("-e")){
                String filename = parameters.get("-e");
                String entityName = parameters.get("-entity");
                String exportMode = parameters.get("-ex_mode") != null ? parameters.get("-ex_mode") : "o" ;
                Entity entity = Controller.getInstance().getProject().getEntityByName(entityName);
                ExcelStatisticsExporter exporter = new ExcelStatisticsExporter();
                exporter.setMode(exportMode);
                exporter.export(entity, filename);
            }
        }
    }
}
